// pages/video/video.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    src:'https://v.qq.com/x/cover/mzc00200geeo83i/u09272bkivl.html',
    danmuList:[
      {text: '第1s出现的弹幕', color:'#fff0000',time:1},
      { text: '第3s出现的弹幕', color: '#fff00ff', time: 3 }
    ],
    movieList:[{
      create_time:'2018-2-2 12:02:32', title:'海边随拍',
      src:'https://www.imooc.com/video/19372.mp4'
    },{
      create_time:'2018-2-2 12:02:32', title: '勿忘心安',
      src: ''
    },{
      create_time:'2018-2-2 12:02:32', title: '点滴记忆',
      src: ''
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 弹幕功能
  videoContext:null,
  inputValue:'',
  onReady:function(){
    this.videoContext = wx.createVideoContext('myVideo')
    const TxvContext = requirePlugin('tencentvideo')
    var txvContext = TxvContext.getTxvContext('txv1')
    txvContext.play()
    txvContext.pause()
  },
  bindInputBlur:function(e){
    this.inputValue = e.detail.value
  },
  bindSendDanmu:function(){
    this.videoContext.sendDanmu({
      text:this.inputValue,
      color:'#f90'
    })
  },
  bindButtonTap:function(){
    wx.chooseVideo({
      sourceType:['album','camera'],
      maxDuration:60,
      camera:'back',
      success:res =>{
        this.setDate({
          src:res.tempFilePath
        })
      }
    })
  }
})